// pages/my/address/address.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
      addressList:''
    },
    getAddressList(){
      let that=this
      wx.request({
          url: app.globalData.api+'getAddressList?userid='+wx.getStorageSync('user').userId,
          success:function(res){
         
            console.log(res.data.data)
            that.setData({
              addressList:res.data.data
             
            })
            console.log(that.data)
          }
        })
    },
    delectAddress:function (e) {
      
      let that=this;
      wx.showModal({
        title: '提示',
        content: '是否删除',
        success(res){
          if(res.confirm){
          wx.request({
            url: app.globalData.api+'delectAddress?addid='+e.currentTarget.dataset.id,
            success(e){
              wx.showModal({
                title: '提示',
                content: '删除成功！',
                showCancel:false
              })
              that.getAddressList()
            }
          })
        }
        }
      })
    },
    updateAddress:function(e){
      const data = {
        describe:e.currentTarget.dataset.id.describe,
        gpsAddr:e.currentTarget.dataset.id.gpsAddr,
        id:e.currentTarget.dataset.id.id,
        name:e.currentTarget.dataset.id.name,
        phone:e.currentTarget.dataset.id.phone,
        userId:e.currentTarget.dataset.id.userId
      }

      console.log(e.currentTarget.dataset.id)
      wx.navigateTo({
        url: '../updateAddress/updateAddress',
        success(res){
          res.eventChannel.emit('ccc',data)
        }
      })
    } ,
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        wx.request({
          url: 'url',
        })
    },
    
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

      this.getAddressList()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})